﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using M2B.GestionEntretiens.Contracts;
using M2B.GestionEntretiens.POCOS;

namespace M2B.GestionEntretiens.Models
{
    public class TestsModel
    {
        #region Properties
        /// <summary>
        /// Tests Service
        /// </summary>
        private ITestsService _testsService;
        /// <summary>
        /// La liste des Tests
        /// </summary>
        public IEnumerable<Test> Tests { get {
            if (_testsService == null) return null;
            var tests =  _testsService.GetTests();
            return tests;
        } }

        #endregion

        #region Constructeurs

        public TestsModel(ITestsService testsService)
        {
            _testsService = testsService;
           
        }
        #endregion
        #region Méthodes
        /// <summary>
        /// Récupération d'un test
        /// </summary>
        /// <param name="testId">Id</param>
        /// <returns></returns>
        public Test GetTest(int testId)
        {
            return Tests.FirstOrDefault(el => el.TestId == testId);
        }
        #endregion
        /// <summary>
        /// Ajouter uin test
        /// </summary>
        /// <param name="test">Test</param>
        public void CreateTest(Test test)
        {
            _testsService.AddTest(test);
        }
        /// <summary>
        /// Supprimer un test
        /// </summary>
        /// <param name="testId">Id Test</param>
        public void DeleteTest(int testId)
        {
            _testsService.DeleteTest(testId);
        }
        /// <summary>
        /// Mise à jour d'un test
        /// </summary>
        /// <param name="test">Test</param>
        public void Update(Test test)
        {
            _testsService.Update(test);
        }
    }
}